package com.adou.d13;

import com.adou.d8.d5.A;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class Collection2 {
    public static void main(String[] args) {
        Collection<String>  c = new ArrayList<>();
        c.add("赵敏");
        c.add("小赵");
        c.add("素素");
        c.add(null);
        c.add("灭绝");
        System.out.println(c);

        // 使用迭代器遍历集合
        Iterator<String> iterator = c.iterator();
//        System.out.println(iterator.next());
//        System.out.println(iterator.next());
//        System.out.println(iterator.next());
//        System.out.println(iterator.next());

        // 多取一次
//        System.out.println(iterator.next());//NoSuchElementException

        while (iterator.hasNext()) {
            String ele = iterator.next();
            System.out.println(ele);
        }
        
        // 增强for
        System.out.println("//////////////增强for");
//        c.clear();
//        c= null; //NullPointerException
//        for (String s : c) {
//            System.out.println(s);
//        }

        // Lambada表达式遍历集合
        System.out.println("//////////////-Lambada表达式遍历集合");
//        c.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });

//        c.forEach((s) ->System.out.println(s));

        c.forEach(System.out::println);
    }
}
